package com.project.controller;

import com.project.bean.ClassBean;
import com.project.service.IClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("class")
public class ClassController {
    @Autowired
    private IClassService service;
    /**
     * 查询所有班级
     * @return 返回班级集合
     */
    @RequestMapping("findAll")
    public List<ClassBean> findAll(){
        return service.findAll();
    }

    /**
     *  按id删除班级
     *   统计指定班级的人数，如果为0，则完成班级删除，返回true，如果不为0，返回false
     * @param id 班级id
     * @return  返回是否删除成功
     */
    @RequestMapping("del")
    public String del(Integer id){
        if (service.del(id)){
            return "ok";
        }else {
            return "no";
        }
    }

    /**
     * 添加班级
     * @param classBean 班级对象
     */
    @RequestMapping("add")
    public String add(ClassBean classBean){
        service.add(classBean);
        return "ok";
    }
}
